package com.my.study.util;

import com.my.study.redisson.model.ClientInfo;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

/**
 * @author: yidujun
 * @create: 2021/11/08 15:55
 */
@Component
public class SpringPlusUtils implements ApplicationContextAware {

    private static ApplicationContext applicationContext;

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        SpringPlusUtils.applicationContext = applicationContext;
    }


    public static Environment getEnvironment() {
        return applicationContext.getEnvironment();
    }


    public static ClientInfo getClientInfo() {
        Environment environment = getEnvironment();
        return new ClientInfo(IpUtils.getLocalIp(), environment.getProperty("server.port"));
    }

}
